﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Zatify.WebUI.Infrastructure;
using Zatify.Domain.Abstract;
using Zatify.WebUI.Admin.Models;
using Zatify.WebUI.Infrastructure.Filters;
using Zatify.WebUI.Infrastructure.Absrtact;
using Zatify.WebUI.Admin.Helpers;

namespace Zatify.WebUI.Areas.Admin.Controllers
{
    [ZatifyAdminAuthorizeAttribute]
    [Utils.MyRequireHttps]
    public class DefaultsController : AdminBaseController
    {
        private IZatifyRepository repository;

        protected override AdminModules AdminModule
        {
            get
            {
                return AdminModules.Defaults;
            }
        }

        public DefaultsController(IZatifyRepository repository, IZatifyAuthProvider authProvider)
            //: base(authProvider)
        {
            this.repository = repository;
        }

        public ActionResult List()
        {
            var systemDefaultsModel = new SystemDefaultsViewModel()
            {
                BusinessHourFrom = repository.SystemDefaultsGetBusinessHourFrom(),
                BusinessHourTo = repository.SystemDefaultsGetBusinessHourTo()
            };

            ViewData["BusinessHoursFrom"] = Helper.GetBusinessHoursSelectList(systemDefaultsModel.BusinessHourFrom);
            ViewData["BusinessHoursTo"] = Helper.GetBusinessHoursSelectList(systemDefaultsModel.BusinessHourTo);

            return View();
        }

        public ActionResult SaveSystemDefault(SystemDefaultsSaveModelView data)
        {
            if (data != null)
            {
                repository.SystemDefaultUpdate(data.ParamCode, data.Value);
                return Json(true);
            }
            else
            {
                return Json(false);
            }
        }

        //private List<SelectListItem> GetBusinessHoursSelectList(DateTime selected)
        //{
        //    var time = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0);
        //    var timeFormat = "HH:mm";
        //    var timeInterval = 30;

        //    var businessHours = new List<SelectListItem>();

        //    for (int i = 0; i < 48; i++)
        //    {
        //        businessHours.Add(new SelectListItem()
        //        {
        //            Text = time.ToString(timeFormat),
        //            Value = time.ToString(timeFormat),
        //            Selected = (time.TimeOfDay == selected.TimeOfDay)
        //        });

        //        time = time.AddMinutes(timeInterval);
        //    }

        //    return businessHours;
        //}
    }
}
